package com.fbr.bannerplayer;

import android.app.Application;
import android.content.Context;

import androidx.multidex.MultiDex;

import com.danikula.videocache.HttpProxyCacheServer;
import cn.bannerplayerlibrary.view.newbanner.video.VideoManager;

import cn.bannerplayerlibrary.VideoCacheProxy;

/**
 * 存放网络请求地址
 */

public class App extends Application implements VideoCacheProxy.AppWrapper {

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }
    private static App AppInstance;
    private static Context sContext;

    private HttpProxyCacheServer mProxy;

    public static Context getAppContext() {
        return sContext;
    }

    public static App getAppInstance() {
        return AppInstance;
    }


    @Override
    public void onCreate() {
        super.onCreate();
        AppInstance = this;
        sContext = getApplicationContext();

        VideoManager.init();
    }

    @Override
    public HttpProxyCacheServer getVideoCacheProxy() {
        return mProxy == null ? (mProxy = newProxy()) : mProxy;
    }

    private HttpProxyCacheServer newProxy() {
        return new HttpProxyCacheServer.Builder(this).cacheDirectory(VideoCacheProxy.getVideoCacheDir(this)).build();
    }
}
